Skip to content

Postgresql reload#54

Open
matelakat wants to merge 2 commits intosap-oc:stable/sap/3.0from
matelakat:postgresql-reload
Open

Postgresql reload#54
matelakat wants to merge 2 commits intosap-oc:stable/sap/3.0from
matelakat:postgresql-reload

Conversation

@matelakat
Copy link

Reload postgresql's configuration gracefully. See commit messages for the details

echo "SELECT pg_reload_conf();" | psql
EOH
action :nothing
end No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/TrailingBlankLines: Final newline missing. (https://github.com/bbatsov/ruby-style-guide#newline-eof)

group "postgres"
mode 0600
variables(
config: config_needs_reload.sort,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call. (https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma)

source "postgresql_reloadable.conf.erb"
owner "postgres"
group "postgres"
mode 0600

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/NumericLiteralPrefix: Use 0o for octal literals. (https://github.com/bbatsov/ruby-style-guide#numeric-literal-prefixes)

notifies change_notify, "service[postgresql]", :immediately
end

template "#{node['postgresql']['dir']}/postgresql_reloadable.conf" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiteralsInInterpolation: Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)

group "postgres"
mode 0600
variables(
config: config_needs_restart.sort,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call. (https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma)

when TrueClass
'on'
when FalseClass
'off'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliterals)

"'#{value}'"
when TrueClass
'on'
when FalseClass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/CaseIndentation: Indent when as deep as case. (https://github.com/bbatsov/ruby-style-guide#indent-when-to-case)

when String
"'#{value}'"
when TrueClass
'on'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliterals)

formatted_value = case value
when String
"'#{value}'"
when TrueClass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/CaseIndentation: Indent when as deep as case. (https://github.com/bbatsov/ruby-style-guide#indent-when-to-case)

raw_configuration.each do |key, value|
next if value.nil?
formatted_value = case value
when String

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/CaseIndentation: Indent when as deep as case. (https://github.com/bbatsov/ruby-style-guide#indent-when-to-case)

Mate Lakat added 2 commits July 19, 2017 15:29
Move out logic from the template to the cookbook, so it can be re-used
later.
This change splits the postgresql configuration file into two pieces.
One should contain the options that require a server restart (the main
postgresql.conf file) and that is sourcing the other file
(postgresql_reloadable.conf) which is the home for reloadable
parameters. This way we can use chef's notification mechanism to either
reload or restart the server.

Please consult postgresql's manual for reloadable configuration options.
If you want to be able to gracefuly reload a specific parameter, amend
that to `reloadable_parameters`
EOH
action :nothing
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/TrailingBlankLines: 1 trailing blank lines detected. (https://github.com/bbatsov/ruby-style-guide#newline-eof)

Copy link

@cmurphy cmurphy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Will try to do a more thorough review tomorrow.

end

reloadable_parameters = [
"log_line_prefix"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think log_truncate_on_ration and log_filename are also reloadable.

Postgresql can be queried for whether a parameter requires a reload or restart with "select context from pg_settings where name = 'log_line_prefix';", maybe at some point in the future we could utilize that.

@matelakat
Copy link
Author

Kicked off another run of the CI

Copy link

@DavidRabel-b1 DavidRabel-b1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me and it works(, now that my mysterious logging problem is gone). ;)

variables(
config: config_needs_restart.sort
)
notifies change_notify, "service[postgresql]", :immediately
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing an issue for me, it seems that this causes the service to be immediately reloaded after the template change, but before the postgresql_reloadable.conf exists, so postgresql fails due to a syntax error because the incuded file doesn't exist yet.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that could be true indeed. I did not run into that trouble, as the HA restart was still broken on my branch.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happened to be checking it in non-ha mode.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me add a fix for that.

@matelakat
Copy link
Author

The reload need to be fixed - as per colleen's report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants